﻿Imports System.Collections.ObjectModel
Imports BusinessEntityObjects
Imports DataLayer
'
<System.ComponentModel.DataObject()> Public Class ContactBLL

#Region " Constructors "

    Public Sub New()
    End Sub

#End Region

#Region " Methods "

    Public Function Count() As Integer
        Return ContactDAL.CreateInstance.Count
    End Function

    Public Function Create() As Contact

        Dim obj As New Contact
        obj.ActiveRuleSet = "Insert"
        obj.CheckAllRules()
        Return obj
    End Function

    Public Shared Function CreateInstance() As ContactBLL
        Return New ContactBLL
    End Function

    <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Delete, True)> _
    Public Function Delete(ByVal obj As Contact) As Integer
        Return ContactDAL.CreateInstance.Delete(obj)
    End Function

    Public Function FillDropDown() As List(Of ContactSearchResult)
        Return ContactDAL.CreateInstance.FillDropDown
    End Function

    Public Function GetFeeds() As List(Of ContactFeed)
        Return ContactDAL.CreateInstance.GetFeeds
    End Function

    <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Insert, True)> _
    Public Function Insert(ByVal obj As Contact, ByRef intNewId As Integer) As Integer

        If obj.HasBeenValidated Then
            Return ContactDAL.CreateInstance.Insert(obj, intNewId)

        Else
            Throw New InvalidOperationException("Contact has not yet been validated for insert.")
        End If

    End Function

    Public Function SearchByLastName(ByVal strSearchString As String) As List(Of ContactSearchResult)
        Return ContactDAL.CreateInstance.SearchByLastName(strSearchString)
    End Function

    <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _
    Public Function [Select](ByVal intId As Integer) As Contact

        Dim obj As Contact = ContactDAL.CreateInstance.Select(intId)

        If obj IsNot Nothing Then
            obj.EndLoading()
        End If

        Return obj
    End Function

    Public Function SelectAll() As ObservableCollection(Of Contact)
        Return ContactDAL.CreateInstance.SelectAll()
    End Function

    <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Update, True)> _
    Public Function Update(ByVal obj As Contact) As Integer

        If obj.HasBeenValidated Then
            Return ContactDAL.CreateInstance.Update(obj)

        Else
            Throw New InvalidOperationException("Contact has not yet been validated for update.")
        End If

    End Function

    'TODO - developers uncomment to recreate database
    'Public Sub CreateDataBase()
    '    ContactDAL.CreateInstance.CreateDataBase()
    'End Sub
#End Region

End Class
